<%@ page contentType="text/html;charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta charset="UTF-8">
<title>Table</title>

<link rel="stylesheet"
	href="<%=request.getContextPath()%>/js/layui-v1.0.9_rls/layui/css/layui.css"
	media="all" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/js/layui-v1.0.9_rls/layui/css/global.css"
	media="all">
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/js/plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/js/layui-v1.0.9_rls/layui/css/table.css" />

<link rel="stylesheet" href="<%=request.getContextPath()%>/css/file.css"
	media="all" />
	

<script type="text/javascript"
	src="<%=request.getContextPath()%>/js/layui-v1.0.9_rls/layui/layui.js"></script>

<script type="text/javascript"
	src="<%=request.getContextPath()%>/js/jquery-1.8.0.min.js"></script>

<script type="text/javascript"
	src="<%=request.getContextPath()%>/js/util.js"></script>


<script type="text/javascript">
		
	
	function createCallBack(reqNo){
	
		parent.$("#queryBtn").click();
		util.closeDivWin();
		
	}
	
	$(document).ready(function(){
	layui.use([ 'upload', 'form', 'laydate','layer'], function() {
	
	
	
	
		layer = layui.layer;
	
		form = layui.form();
		
		
		
		//监听提交
		form.on('submit(saveBtn)', function(data) {
		
			var reqNo = $("#reqNo").val();
			var stepId = $("#nextStepId").val();
			var stepName = $("#stepName").val();
			var opNo = $("#opNo").val();
			var opName = $("#opNo").find("option:selected").text(); 
			var taskId = $("#taskId").val();
			var dealType = $("#dealType").val();
			var opDesc = $("#opDesc").val();
			var serviceTime = $("#serviceTime").val();
			
			
			$.post("<%=request.getContextPath()%>/rms/submitTask",
			
						{
						"reqInfo.reqNo":reqNo,
						"reqInfo.stepId":stepId,
						"reqInfo.sts":"0",
						"taskInfo.taskId":taskId,
						"taskInfo.dealType":dealType,
						"taskInfo.opDesc":opDesc,
						"nextTaskInfo.stepId":stepId,
						"nextTaskInfo.taskName":stepName,
						"nextTaskInfo.opNo":opNo,
						"nextTaskInfo.opName":opName
						
						},
					
				function(data){
			
					if(data.retCode == "0"){
					 	var reqNo = data.reqInfo.reqNo;
						util.showDialog("提交任务成功！",2,"retT=createCallBack('"+reqNo+"')");
					}else{
						util.showDialog("提交任务异常，请联系管理员！",0);
					}
			},"json");
			

			return false;
		});
		
		//需求分类变更事件监听
		form.on('select(dealType)', function(data){
		
		
			var dealType = data.value;
			var reqNo = $("#reqNo").val();
			var procId = $("#procId").val();	
			var stepId = $("#stepId").val();
			
			
			//获取下一步处理人
			$.post("<%=request.getContextPath()%>/rms/nextStep",{"opCfg.dealType":dealType,"opCfg.procId":procId,"opCfg.stepId":stepId,"opCfg.reqNo":reqNo},
				function(data){
			
					var nextOp = "<select lay-filter='opNo' id='opNo' name='opNo' lay-verify='required' lay-search=''>";
							
					var opList = data.opList;
					for(var i = 0; i < opList.length; i++){
					
						var opInfo = opList[i];
						nextOp = nextOp + "<option value='"+opInfo.opNo+"'>"+opInfo.opName+"</option>";
						
					}
					
					nextOp = nextOp + "</select>"
					
					$("#opDiv").html(nextOp);
					form.render('select');
					
					$("#nextStepId").val(opInfo.stepId);
					$("#stepName").val(opInfo.stepName);
				
			});
			
		 });
		  				
			  				

		var upload = layui.upload;
		//上传文件
		layui.upload({
							url : '<%=request.getContextPath()%>/rms/uploadAttach?reqInfo.reqNo=<s:property value="reqInfo.reqNo"/>'
									,
									title : '上传文件',
									ext : 'jpg|png|gif|rar|doc|docx|xls|xlsx|zip',
									method : 'post' //上传接口的http类型
									//上传前
									,
									before : function(input) {

										//返回的参数item，即为当前的input DOM对象
										//console.log('文件上传中');
									},
									success : function(res) {

										var fileName = decodeURI(res.fileName);
										var saveName = res.saveName;
										var fileStr = '<div class="layui-form-item"><div class="layui-inline "><a href="javascript:void(0)" onclick=util.downloadFile("<%=request.getContextPath()%>/rms/downloadFile","'+saveName+'","'+fileName+'")>'+fileName+'</a><a style="margin-left:10px" href="javascript:void(0)" data-id="1" data-opt="del" class="layui-btn layui-btn-danger layui-btn-mini">删除</a></div></div>';
										//alert(fileStr);
										$("#attachFileDiv").append(fileStr);

										//alert(res.retCode);
										//console.log(res); //如：{"code":0 ,"msg":"","url":"http://cdn.abc.com/123.jpg"'} 
										//alert(res.url);
									}
								});

						//日期控件格式控制
						var laydate = layui.laydate;
						var reqTimeObj = {
							format : 'YYYY-MM-DD hh:mm:ss',
							istime : true
						};
						reqTimeObj.elem = document.getElementById('serviceTime');
						document.getElementById('serviceTime').onclick11 = function() {
							reqTimeObj.elem = this;
							laydate(reqTimeObj);
						}
						//reqTimeObj.laydate();
						//laydate.laydate({"elem: 'reqTime',format: 'YYYY-MM-DD hh:mm:ss'"});
						
						
						
						
						
						
					

		});
	});
	
	//反馈按钮处理
	function cancel() {

		parent._closeTab("发起需求");
	}

	function addTabTest() {
		parent._addTab("测试2", "http://www.sina.com.cn");
	}

	//下载附件
	function downLoadFile(saveName) {
		alert(saveName);
	}
	
	//获取下一环节信息
	function getNextStepInfo(){
		alert(1);
	}
</script>
</head>
<body style="background: white">
	<div style="margin: 15px;">
		
		<iframe src="" name="down_frame" id="down_frame" style="display:none"
			frameborder="0" scrolling="auto">
		</iframe> 
		
		<form class="layui-form">
		
			<s:hidden name="taskInfo.taskId" id="taskId"></s:hidden>
			<s:hidden name="taskInfo.reqNo" id="reqNo"></s:hidden>
			<s:hidden name="taskInfo.stepId" id="stepId"></s:hidden>
			<s:hidden name="taskInfo.procId" id="procId"></s:hidden>

			<div class="layui-form-item">
				<label class="layui-form-label">需求名称</label>
				<div class="layui-input-block">
					<input type="text" lay-verify="required" id="reqName"
						name="reqName" placeholder="需求名称" autocomplete="off"
						class="layui-input" value="<s:property value="taskInfo.reqName"/>" readonly>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">任务名称</label>
				<div class="layui-input-block">
					<input type="text" lay-verify="required" id="reqName"
						name="reqName" placeholder="" autocomplete="off"
						class="layui-input" value="<s:property value='taskInfo.taskName'/>" readonly>
				</div>
			</div>


			<div class="layui-form-item">
				<label class="layui-form-label">要求完成时间</label>

				<div class="layui-input-inline">
					<input type="text" name="requiredTime" id="requiredTime" 
						placeholder="要求完成时间" autocomplete="off" class="layui-input" value="<s:property value='taskInfo.requiredTime'/>" readonly>
				</div>
				
				<label class="layui-form-label" style="width:150px">厂家确认完成时间</label>

				<div class="layui-input-inline">
					<input type="text" name="serviceTime" id="serviceTime" 
						placeholder="厂家确认完成时间" autocomplete="off" class="layui-input" value="<s:property value='taskInfo.serviceTime'/>" readonly>
				</div>

			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">处理方式</label>
				<div class="layui-input-inline">
						<select id = "dealType" lay-filter="dealType" name="dealType" lay-verify="required" lay-search="">
							<option value=""></option>
							<option value="0">通过</option>
							<option value="1">退回</option>
			
						</select>
					</div>
						
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">下一环节</label>
				<div class="layui-input-inline">
					<input type="hidden" id="nextStepId" value="">
					<input type="text" name="stepName" id="stepName" 
						placeholder="" autocomplete="off" class="layui-input" value="" readonly>
				</div>
				
				<label class="layui-form-label">处理人</label>
				<div class="layui-input-inline" id="opDiv">
				
				</div>
			</div>



			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">处理备注</label>
				<div class="layui-input-block">
					<textarea lay-verify="required" id="opDesc" name="opDesc"
						placeholder="处理备注" class="layui-textarea"></textarea>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<!-- lay-filter就是id属性 -->
					<button class="layui-btn" lay-submit="" lay-filter="saveBtn">提交</button>
					<input type="button" class="layui-btn " onclick="util.closeDivWin()"
						value="取消"></input> 
				</div>
			</div>

		</form>

	</div>
</body>
</html>